from django.utils.deprecation import MiddlewareMixin

"""自定义中间件"""


class TestMiddleware1(MiddlewareMixin):

    def process_request(self, request):
        """处理请求前自动调用"""
        print('TestMiddleware1 -> process_request 被调用')

    def process_view(self, request, view_func, view_args, view_kwargs):
        # 处理视图前自动调用
        print('TestMiddleware1 ->  process_view 被调用')

    def process_response(self, request, response):
        """在每个响应返回给客户端之前自动调用"""
        print('TestMiddleware1 ->  process_response 被调用')
        return response

class TestMiddleware2(MiddlewareMixin):

    def process_request(self, request):
        """处理请求前自动调用"""
        print('TestMiddleware2 -> process_request 被调用')

    def process_view(self, request, view_func, view_args, view_kwargs):
        # 处理视图前自动调用
        print('TestMiddleware2 ->  process_view 被调用')

    def process_response(self, request, response):
        """在每个响应返回给客户端之前自动调用"""
        print('TestMiddleware2 ->  process_response 被调用')
        return response